package com.ycy.smartcourseselection.controller;


import com.ycy.smartcourseselection.common.ResData;
import com.ycy.smartcourseselection.dto.login.LoginDTO;
import com.ycy.smartcourseselection.dto.token.TokenInfoDTO;
import com.ycy.smartcourseselection.dto.token.UserInfo;
import com.ycy.smartcourseselection.service.LoginService;
import com.ycy.smartcourseselection.utils.TokenUtils;
import com.ycy.smartcourseselection.vo.login.GetQrCodeRes;
import com.ycy.smartcourseselection.vo.login.ScanQrCodeRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "登录")
@RestController
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    @ApiOperation("登 录")
    public ResData<String> login(@RequestBody LoginDTO loginDTO) {
        return loginService.login(loginDTO);
    }

    @PostMapping("/getInfoByToken")
    @ApiOperation("通过token获取个人信息")
    public ResData<UserInfo> getInfoByToken(@RequestBody TokenInfoDTO tokenInfoDTO) {
        return TokenUtils.getInfoByToken(tokenInfoDTO);
    }

    @GetMapping("/loginByQrCode")
    @ApiOperation(value = "扫码登录",notes = "前端轮询的方法,带时间戳查询该时间戳时申请的二维码是否被扫描等信息")
    public ResData<String> loginByQrCode(String timeStamp) {
        return loginService.loginByQrCode(timeStamp);
    }
}
